home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Various / DevDisk 65 (1989)(DevWare PD).zip / DevDisk 65 (1989)(DevWare PD).adf / mypixel / mypixel.c < prev    next >
C/C++ Source or Header  |  1990-07-11  |  3KB  |  152 lines

  1. /*
  2.  *  pixel.c   -  Tom Eshelman  -  Reading, Pa.   12/11/88
  3.  *
  4.  *  Program to draw a pixel display using the assembly routine, _pixel.
  5.  *  C call is -  pixel (&bmap, color, x, y); where color = simple constant.
  6.  *  No interpretation of colors is required.
  7. */
  8.  
  9.  
  10. #include <exec/types.h>
  11. #include <graphics/gfxbase.h>
  12. #include <graphics/gfx.h>
  13. #include <graphics/view.h>
  14. #include <graphics/rastport.h>
  15. #include <functions.h>
  16.  
  17. #define DEPTH     5L
  18. #define WIDTH     320L
  19. #define HEIGHT    200L
  20.  
  21. #define VPWIDTH   320L
  22. #define VPHEIGHT  200L
  23. #define NUMCOLS   32L
  24.  
  25. struct  View      view;
  26. struct  ViewPort  vport;
  27. struct  ColorMap  *cm;
  28.  
  29. struct  RastPort  rport;
  30. struct  BitMap    bmap;
  31. struct  RasInfo   ri;
  32.  
  33. struct  GfxBase   *GfxBase;
  34. struct  View      *oldview;
  35.  
  36. UWORD palette[] =
  37. {
  38.    0x000, 0x00c, 0x04e, 0x08f, 0x0cc, 0x0e5, 0x0f0, 0xdf0,
  39.    0xee0, 0xfc0, 0xe90, 0xf42, 0xe06, 0xd0a, 0xb0c, 0x90c,
  40.  
  41.    0x70c, 0x111, 0x222, 0x333, 0x444, 0x555, 0x666, 0x777,
  42.    0x888, 0x999, 0xaaa, 0xbbb, 0xccc, 0xddd, 0xeee, 0xfff
  43. };
  44.  
  45.  
  46. extern void pixel();                      /* Here is our Assembly Routine! */
  47.  
  48.  
  49.  
  50. void main()
  51. {
  52.    register short  i, j;
  53.  
  54.    if ( ! (GfxBase = (struct GfxBase*) OpenLibrary ("graphics.library", 0L)))
  55.        CloseAll();
  56.  
  57.    oldview = GfxBase->ActiView;
  58.  
  59.    make_playfields();
  60.  
  61.    for ( j = 0; j < 200; j++ )               /* For each of 200 lines..*/
  62.  
  63.       for ( i = 0; i < 320; i++ )            /* Draw 320 pixels.     */
  64.  
  65.          pixel ( &bmap, j, i, j );                  /* color no., x, y */
  66.  
  67.    Delay (100L);
  68.  
  69.    for ( j = 199; j >= 0; j-- )              /* Erase lines in reverse. */
  70.  
  71.       for ( i = 319; i >= 0; i-- )
  72.  
  73.          pixel ( &bmap, 0, i, j );                  /* color, x, y */
  74.  
  75.    CloseAll();
  76. }
  77.  
  78.  
  79. make_playfields ()                  /* The usual graphics setup, as seen   */
  80. {                                   /* in nearly every program in the P.D. */
  81.    short   i;
  82.  
  83.    InitView (&view);
  84.    InitVPort (&vport);
  85.  
  86.    view.ViewPort = &vport;
  87.  
  88.    cm = (struct ColorMap*) GetColorMap (NUMCOLS);
  89.  
  90.    vport.ColorMap = cm;
  91.  
  92.    vport.DWidth  = VPWIDTH;
  93.    vport.DHeight = VPHEIGHT;
  94.    vport.RasInfo = &ri;
  95.    vport.Modes   = 0;
  96.  
  97.    InitBitMap (&bmap, DEPTH, WIDTH, HEIGHT);
  98.  
  99.    for (i = 0; i < DEPTH; i++)
  100.    {
  101.       if ( !(bmap.Planes[i] = (PLANEPTR) AllocRaster (WIDTH, HEIGHT)))
  102.  
  103.          CloseAll();
  104.  
  105.       BltClear (bmap.Planes[i], RASSIZE ( WIDTH, HEIGHT ), 0L);
  106.    }
  107.  
  108.    ri.BitMap   = &bmap;
  109.  
  110.    ri.RxOffset = 0;
  111.    ri.RyOffset = 0;
  112.  
  113.    ri.Next = NULL;
  114.  
  115.    InitRastPort (&rport);
  116.    rport.BitMap = &bmap;
  117.  
  118.    MakeVPort (&view, &vport);
  119.    MrgCop (&view);
  120.  
  121.    LoadRGB4 ( &vport, &palette[0], NUMCOLS );
  122.  
  123.    LoadView (&view);
  124. }
  125.  
  126.  
  127.  
  128. CloseAll()
  129. {
  130.    short  i;
  131.  
  132.    for (i = 0; i < DEPTH; i++)
  133.    {
  134.       if (bmap.Planes[i])
  135.          FreeRaster ((char*) bmap.Planes[i], WIDTH, HEIGHT);
  136.    }   
  137.  
  138.    if (cm)
  139.       FreeColorMap (cm);
  140.  
  141.    FreeVPortCopLists (&vport);               /* Because of MakeVPort */
  142.    FreeCprList (view.LOFCprList);            /* and MrgCop calls.    */
  143.  
  144.    LoadView (oldview);
  145.  
  146.    Delay(50L);
  147.  
  148.    CloseLibrary((long)GfxBase);
  149.  
  150. }   
  151.  
  152.